<!--
Copyright 2003 Cordys R&D B.V. 

This file is part of the Cordys SAP Connector. 

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!--
 Project  : Cordys BAC
 File Name : keyStoreMain.htm
 Description : This UI is usd to add contextmenus to the items on the left menu and to call the applications .
-->

<html xmlns:eibus onselect="addContextMenu()">
    <head>
       <link rel="stylesheet" href="/cordys/wcp/style/behaviors.css"/>
       <title></title>
	   <script language="javascript">
	   var editApplication;
	   var contextedItem;
	   var uniqueFilePath;	   
	   /*Function Name : addContextMenu
			Scope : This is to add  contextmenus to the items on the left menu and to call the right application
					onclick.*/	   
	   function addContextMenu()
	   {			
			var selectedItem = window.event.data.menuItem;
			var exploreType = window.event.data.exploreType;
			applicationDef = window.event.applicationDefinition;
			cmContextMenu.registerHTML(selectedItem);
			uniqueFilePath=applicationDef.selectSingleNode(".//url").text.substring(0,applicationDef.selectSingleNode(".//url").text.lastIndexOf("/")+1);
			if(exploreType=="select")
			{				
				editApplication=menuApplication.cloneNode(true);
				editApplication.selectSingleNode(".//url").text=uniqueFilePath+"listkeystores.htm";
				editApplication.selectSingleNode(".//id").text="KeyStores Repository"
				editApplication.selectSingleNode(".//caption").text="KeyStores Repository"
				editApplication.selectSingleNode(".//description").text="KeyStores Repository"
	   			application.select(editApplication.documentElement);
			}
			if(exploreType=="expand")
			{				
				var root,index=0;
				var count=0;
				var keyStoreArray=new Array();
				var env=new ActiveXObject("Microsoft.XMLDOM");
				var LDAPkeystorePath="";
				var cloneGetKeyStore = getKeyStoreXML.XMLDocument.cloneNode(true);
				selectedItem.getChildContainer().innerHTML = "";				
				cloneGetKeyStore.selectSingleNode("SOAP:Envelope/SOAP:Body/GetSoapProcessors/dn").text =application.organization;
				digetEntries.clear();
				digetEntries.request=cloneGetKeyStore;
				digetEntries.reset();
				if(digetEntries.data.selectSingleNode(".//bussoapprocessorconfiguration"))
				{
					var keyStoreList=digetEntries.data.getElementsByTagName("bussoapprocessorconfiguration");
					for(var i=0;i<keyStoreList.length;i++)
					{
						env.loadXML(keyStoreList[i].selectSingleNode(".//string").text);
						var implementation=env.selectSingleNode(".//configurations/configuration").getAttribute("implementation");
						if(implementation == null) continue;
						if(implementation=="com.eibus.applicationconnector.sap.SAPMapper")
						{
							/*for(var j=0;j<env.selectSingleNode(".//env").getAttribute("keyStoreLoc").length;j++)
							{
								character=(env.selectSingleNode(".//env").getAttribute("keyStoreLoc")).charAt(j);
								if(character==":" || character==":")
								{
									index=j;
								}
							}
							if(index>0)
								LDAPkeystorePath=env.selectSingleNode(".//env").getAttribute("keyStoreLoc").substring(index+1,env.selectSingleNode(".//env").getAttribute("keyStoreLoc").length);
							var keyPath=env.selectSingleNode(".//env").getAttribute("keyStoreLoc");
							var flag=0;
							for(var k=0;k<keyStoreArray.length;k++)
							{
								if(keyPath.toUpperCase()==keyStoreArray[k].toUpperCase())
								{
									flag=1;
									break;
								}
							}
							if(flag==0)
							{*/
							if(env.selectSingleNode(".//env").getAttribute("protocol") == "https")
							{
								//keyStoreArray[count++]=keyPath;
								LDAPkeystorePath = env.selectSingleNode(".//env").getAttribute("keyStoreLoc");
								var applications = menuApplication.cloneNode(true);
								applications.selectSingleNode(".//url").text=uniqueFilePath+"aliasexplorer.htm";
								applications.selectSingleNode(".//id").text="Alias"+i;
								applications.selectSingleNode(".//caption").text=LDAPkeystorePath;
								applications.selectSingleNode(".//description").text=LDAPkeystorePath;//
								applications.selectSingleNode(".//keystorePath").text=env.selectSingleNode(".//env").getAttribute("keyStoreLoc");
								applications.selectSingleNode(".//type").text=env.selectSingleNode(".//env").getAttribute("type");;
								applications.selectSingleNode(".//provider").text=env.selectSingleNode(".//env").getAttribute("provider");
								applications.selectSingleNode(".//passwd").text=env.selectSingleNode(".//env").getAttribute("keyStorePasswd");
								selectedItem.addItem(applications.documentElement);
							}
						}
					}
				}
	   		}
	   	}	   	
	    /*Function Name : refresh
			Scope : This is called when the refresh option is selected from the contextmenu.This will get the list of
			keystores again and show under the node.*/
	   function refresh()
	   {
			var root,index=0;
	   		var count=0;
			var keyStoreArray=new Array();
			var cloneGetKeyStore = getKeyStoreXML.XMLDocument.cloneNode(true);
			var env=new ActiveXObject("Microsoft.XMLDOM");
			var LDAPkeystorePath = "";
			contextedItem = window.event.activeElement.getTreeItem();
	   		contextedItem.getChildContainer().innerHTML = "";		
			cloneGetKeyStore.selectSingleNode("SOAP:Envelope/SOAP:Body/GetSoapProcessors/dn").text =application.organization;
			digetEntries.request=cloneGetKeyStore;
			digetEntries.reset();
			if(digetEntries.data.selectSingleNode(".//bussoapprocessorconfiguration"))
			{
				var keyStoreList=digetEntries.data.selectNodes("bussoapprocessorconfiguration");
				for(var i = 0;i < keyStoreList.length; i++)
				{
					env.loadXML(keyStoreList[i].selectSingleNode(".//string").text);
					var implementation=env.selectSingleNode(".//configurations/configuration").getAttribute("implementation");
					if(implementation=="com.eibus.applicationconnector.sap.SAPMapper")
					{
						/*for(var j = 0;j < env.selectSingleNode(".//env").getAttribute("keyStoreLoc").length ; j++)
						{
							character=(env.selectSingleNode(".//env").getAttribute("keyStoreLoc")).charAt(j);
							if(character=="\\" || character=="//" )
							{
								index=j;
							}
						}
						if(index > 0)
							LDAPkeystorePath = env.selectSingleNode(".//env").getAttribute("keyStoreLoc").substring(index+1,env.selectSingleNode(".//env").getAttribute("keyStoreLoc").length);
						var keyPath = env.selectSingleNode(".//env").getAttribute("keyStoreLoc");
						var flag = 0;
						for(var k = 0;k < keyStoreArray.length ;k++)
						{
							if(keyPath.toUpperCase()== keyStoreArray[k].toUpperCase())
							{
								flag=1;
								break;
							}
						}
						if(flag == 0 && LDAPkeystorePath!="")
						{*/
						if(env.selectSingleNode(".//env").getAttribute("protocol") == "https")
						{
							//keyStoreArray[count++]=keyPath;
							LDAPkeystorePath = env.selectSingleNode(".//env").getAttribute("keyStoreLoc").substring(index+1,env.selectSingleNode(".//env").getAttribute("keyStoreLoc").length);
							LDAPtype=env.selectSingleNode(".//env").getAttribute("type");
							LDAPprovider=env.selectSingleNode(".//env").getAttribute("provider");
							LDAPpasswd=env.selectSingleNode(".//env").getAttribute("keyStorePasswd");
							var applications = menuApplication.cloneNode(true);
							applications.selectSingleNode(".//url").text=uniqueFilePath+ "aliasexplorer.htm"
							applications.selectSingleNode(".//id").text=LDAPkeystorePath
							applications.selectSingleNode(".//caption").text=LDAPkeystorePath
							applications.selectSingleNode(".//description").text=LDAPkeystorePath
							applications.selectSingleNode(".//keystorePath").text=env.selectSingleNode(".//env").getAttribute("keyStoreLoc");
   							applications.selectSingleNode(".//type").text=LDAPtype
   							applications.selectSingleNode(".//provider").text=LDAPprovider
   							applications.selectSingleNode(".//passwd").text=LDAPpasswd
							contextedItem.addItem(applications.documentElement);
						}
	   				}
				}
			}
	   }
	   /*Function Name : createKeyStore
			Scope : This is called to create a new keystore*/
	   function createKeyStore()
	   {
			editApplication=menuApplication.cloneNode(true);
	   		editApplication.selectSingleNode(".//url").text=uniqueFilePath+"keyStoredetails.htm"
	   		editApplication.selectSingleNode(".//id").text="NewKeyStore"
	   		editApplication.selectSingleNode(".//caption").text="Create new KeyStore"
	   		editApplication.selectSingleNode(".//description").text="Create new KeyStore"
   			application.select(editApplication.documentElement);

	   }
	   /*Function Name : showGatewayError
			Scope : This is to hide the gateway error and show only the fault information.*/
	   function showGatewayError()
		{
			window.event.errorText = false;
			alert("Error occured in the gateway.Please contact the administrator to find the details");
			
		}
		
		/*Function Name : showFault
			Scope : This is to hide the soapfaults and show only the fault information.*/
		function showFault()
		{
			window.event.errorText = false;
			alert(window.event.errorText);			
		}
	   </script>
	</head>
	<eibus:dataisland
		 id = "digetEntries"
		 request = "getEntries.XMLDocument"
		 automatic = "false"
		 onsoapfault = "showFault()"
		 ongatewayerror = "showGatewayError()"
		 async="false"/>
	<xml id = "getKeyStoreXML">
		<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
		    <SOAP:Body>
		        <GetSoapProcessors xmlns="http://schemas.cordys.com/1.0/ldap">
		            <dn></dn>        
		        </GetSoapProcessors>
		    </SOAP:Body>
		</SOAP:Envelope>
	</xml>
	<xml id="treeXml">
		<Application isfolder="true" display="hidden">
		    <description>KeyStore</description>
		    <id>KeyStore</id>
		    <caption>KeyStore</caption>
		    <url>\wcpdev\html\SAP\keystoremain.htm</url>
		</Application>
	</xml>
	<xml id="menuApplication">
		<Application>
			<description></description>
			<id></id>
			<caption></caption>
			<url></url>
			<frame>main</frame>
			<keystorePath></keystorePath>
			<type></type>
			<provider></provider>
			<passwd></passwd>
		</Application>
	</xml>
	<eibus:contextmenu id="cmContextMenu"  class="light" style="display:none">
        <eibus:menuitem onclick="createKeyStore()" class="light">New</eibus:menuitem>
        <eibus:menuitem separator="true"/>
        <eibus:menuitem onclick="refresh()" class="light">Refresh</eibus:menuitem>
    </eibus:contextmenu>    
	<body>
	</body>
</html>